
package model;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Collection;
/**
 *
 * @author NootFer
 */

public class Relatorio {
    
    private Collection<Sessao> sessoesAtuais;
    
    public Relatorio(Collection<Sessao> sessoes){
        sessoesAtuais =  sessoes;
    }
    
    public String createCsvFile(){
        String relatorio;
        relatorio = "Sessao ID;Quantidade de Ingressos Vendidos;Filme;Data e hora\n";
        for(Sessao sessao : sessoesAtuais){
            relatorio = relatorio+sessao.getId() + ";" + sessao.getQtdIngressosVendidos() + ";" + sessao.getFilme().getNome() + ";" + new SimpleDateFormat("dd/MM/yyyy hh:mm").format(sessao.getData()) + "\n";
        }
        return relatorio;
    }
    
    public boolean writeFile (File file, String dataString) {
    try {
       PrintWriter out = new PrintWriter (new BufferedWriter (new FileWriter (file)));
       out.print (dataString);
       out.flush ();
       out.close ();
    }
    catch (IOException e) {
       return false;
    }
    return true;
  }   
    
}
